using System;
using GameStateManagement;
using Microsoft.Xna.Framework;

namespace Life
{
    class MainMenuScreen :  MenuScreen
    {
        // TODO: refactor, too much copy paste

        public MainMenuScreen()
            : base("")
        {
            Vector2 buttonSize = new Vector2(250, 75);

            Button playButton = new Button("Play", buttonSize);
            playButton.Tapped += playButton_Tapped;
            MenuButtons.Add(playButton);

            Button loadButton = new Button("Load", buttonSize);
            loadButton.Tapped += loadButton_Tapped;
            MenuButtons.Add(loadButton);

            Button helpButton = new Button("Help", buttonSize);
            helpButton.Tapped += helpButton_Tapped;
            MenuButtons.Add(helpButton);

            Button exitButton = new Button("Exit", buttonSize);
            exitButton.Tapped += exitButton_Tapped;
            MenuButtons.Add(exitButton);
        }

        void playButton_Tapped(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, null, new GameplayScreen());
        }

        void loadButton_Tapped(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, null, new LoadScreen());
        }

        void helpButton_Tapped(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, null, new HelpScreen());
        }

        void exitButton_Tapped(object sender, EventArgs e)
        {
            OnCancel();
        }

        public override void Activate(bool instancePreserved)
        {
            // Ensure game manager is initialized
            IGameManager gameManager = (IGameManager)Game1.GetService(typeof(IGameManager));
            gameManager.Initialize();

            base.Activate(instancePreserved);
        }

        protected override void OnCancel()
        {
            ScreenManager.Game.Exit();
            base.OnCancel();
        }
    }
}
